// components/setting/index.js
import {
  logout
} from '../../utils/util'
import {
  numSettingsType
} from '../../dataSource'

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    root: {
      type: Boolean,
      observer: 'check'
    },
    show: {
      type: Boolean,
      observer: 'check'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isRoot: false,
    numbers: [{
      name: '采集记录编号',
      url: '/pages/number/index?key='+ numSettingsType.RECORD,
    }, {
      name: '配方编号',
      url: '/pages/number/index?key='+ numSettingsType.RECIPE
    },{
      name: '原料编号',
      url: '/pages/number/index?key='+ numSettingsType.INGREDIENTS
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    check(value) {
      this.setData({
        isRoot: getApp().globalData.root
      })
    },
    onLogout() {
      wx.showModal({
        content: '确定要退出当前账号吗？',
        success(res) {
          if (res.confirm) {
            logout();
          }
        }
      })
    },
    toNumber(event) {
        const url = event.currentTarget.dataset.url;
        wx.navigateTo({
          url
        })
    },
  },
  lifetimes: {
    attached: function () {

    },
    show() {},
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
})